package com.supermarket.model;

import java.sql.Timestamp;

/**
 * 用户实体类
 * 对应数据库中的users表
 */
public class User {
    private int id;
    private String username;
    private String passwordHash;
    private String realName;
    private String phone;
    private String email;
    private String status;
    private Timestamp createdAt;
    private Timestamp updatedAt;
    private Timestamp lastLoginAt; // 最后登录时间
    private String roleName; // 用户角色名称（用于显示）

    // 构造函数
    public User() {
    }

    public User(String username, String realName, String roleName) {
        this.username = username;
        this.realName = realName;
        this.roleName = roleName;
    }

    // Getter和Setter方法
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPasswordHash() {
        return passwordHash;
    }

    public void setPasswordHash(String passwordHash) {
        this.passwordHash = passwordHash;
    }

    public String getRealName() {
        return realName;
    }

    public void setRealName(String realName) {
        this.realName = realName;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public Timestamp getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(Timestamp createdAt) {
        this.createdAt = createdAt;
    }

    public Timestamp getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(Timestamp updatedAt) {
        this.updatedAt = updatedAt;
    }

    public Timestamp getLastLoginAt() {
        return lastLoginAt;
    }

    public void setLastLoginAt(Timestamp lastLoginAt) {
        this.lastLoginAt = lastLoginAt;
    }

    public String getRoleName() {
        return roleName;
    }

    public void setRoleName(String roleName) {
        this.roleName = roleName;
    }

    /**
     * 判断是否为管理员
     */
    public boolean isAdmin() {
        return "管理员".equals(roleName) || "ADMIN".equals(roleName);
    }

    /**
     * 判断是否为收银员
     */
    public boolean isCashier() {
        return "收银员".equals(roleName) || "CASHIER".equals(roleName);
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", username='" + username + '\'' +
                ", realName='" + realName + '\'' +
                ", phone='" + phone + '\'' +
                ", email='" + email + '\'' +
                ", status='" + status + '\'' +
                ", roleName='" + roleName + '\'' +
                '}';
    }
}
